﻿using System.Collections.Generic;
using System.Xml.Linq;
using Engine;

namespace Game
{
    public class MicroWidget : CanvasWidget
    {
        internal class Order
        {
            public Block block;

            public int order;

            public int value;

            public Order(Block b, int o, int v)
            {
                block = b;
                order = o;
                value = v;
            }
        }

        public List<string> m_categories = new List<string>();

        public int m_categoryIndex;

        public int m_listCategoryIndex = -1;

        public GridPanelWidget m_waterpurifierGrid;

        public InventorySlotWidget m_fuelSlot;

        public InventorySlotWidget m_resultSlot;

        public ListPanelWidget m_blocksList;

        public ValueBarWidget m_progress;

        public ButtonWidget m_nextCategoryButton;

        public ButtonWidget m_prevCategoryButton;

        public FCComponentMicro m_fermentation;

        public MicroWidget(IInventory inventory, FCComponentMicro componentMicro)
        {
            m_fermentation = componentMicro;
            XElement node = ContentManager.Get<XElement>("Widgets/MicroWidget");
            LoadContents(this, node);
            m_waterpurifierGrid = Children.Find<GridPanelWidget>("WaterPurifierGrid");
            m_progress = Children.Find<ValueBarWidget>("Progress");
            m_resultSlot = Children.Find<InventorySlotWidget>("ResultSlot");
            m_fuelSlot = Children.Find<InventorySlotWidget>("FuelSlot");
            int num = 0;
            for (int i = 0; i < m_waterpurifierGrid.RowsCount; i++)
            {
                for (int j = 0; j < m_waterpurifierGrid.ColumnsCount; j++)
                {
                    InventorySlotWidget inventorySlotWidget = new InventorySlotWidget();
                    inventorySlotWidget.AssignInventorySlot(componentMicro, num++);
                    m_waterpurifierGrid.Children.Add(inventorySlotWidget);
                    m_waterpurifierGrid.SetWidgetCell(inventorySlotWidget, new Point2(j, i));
                }
            }

            m_fuelSlot.AssignInventorySlot(componentMicro, componentMicro.FuelSlotIndex);
            m_resultSlot.AssignInventorySlot(componentMicro, componentMicro.ResultSlotIndex);
        }

        public override void Update()
        {
            if (!m_fermentation.IsAddedToProject)
            {
                base.ParentWidget.Children.Remove(this);
            }

            m_progress.Value = m_fermentation.SmeltingProgress;
        }
    }
}